package com.bving.crawler.config;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bving.crawler.mapper.CarTestMapper;
import com.bving.crawler.pojo.model.CarTestModel;
import com.bving.crawler.util.TitleFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 *
 * @description
 *
 */
@Configuration
public class TitleFilterCfg {

    @Autowired
    private CarTestMapper carTestMapper;

    @Bean
    public TitleFilter titleFilter(){
        TitleFilter titleFilter;
        //声明页码数
        Integer page=1;
        //声明分页大小
        Integer pageSize=100;
        for (;;){
             titleFilter = new TitleFilter();
            //查询数据库中title数据,因为数据量过大，最好分页查询
            List<CarTestModel> list = carTestMapper.getList(page-1, pageSize);
            for (CarTestModel carTestModel : list) {
                //初始化数据，把数据库中已有数据的汽车标题放到去重过滤器中
                titleFilter.add(carTestModel.getTitle());
            }

            //执行完成后页码加1
            page++;
            //如果最后一页则退出
            if (!pageSize.equals(list.size())){
                break;
            }
        }

        return titleFilter;
    }
}